import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入local
import local from '../utils/local'

Vue.use(VueRouter);

// 通用的路由配置
const routes = [{
        path: '/',
        name: 'Register',
        component: () =>
            import ('../views/Register.vue'),
        // redirect: '/index'//重定向
    },

    {
        path: '/xieyi',
        name: 'Xieyi',
        component: () =>
            import ('../views/Xieyi.vue')
    },
    {
        path: '/index',
        name: 'Index',
        component: () =>
            import ('../views/index.vue')
    },
    {
        path: '/personal',
        name: 'Personal',
        component: () =>
            import ('../views/personal.vue')
    },
    {
        path: '/tixianjilu',
        name: 'Tixianjilu',
        component: () =>
            import ('../views/tixianjilu.vue')
    },
    {
        path: '/password',
        name: 'Password',
        component: () =>
            import ('../views/password.vue')
    },
    {
        path: '/xinzhen',
        name: 'Xinzhen',
        component: () =>
            import ('../views/xinzhen.vue')
    },
    {
        path: '/kabao',
        name: 'Kabao',
        component: () =>
            import ('../views/kabao.vue')
    },
    {
        path: '/CPassword',
        name: 'CPassword',
        component: () =>
            import ('../views/CPassword.vue')
    },
    {
        path: '/tixian',
        name: 'Tixian',
        component: () =>
            import ('../views/tixian.vue')
    },
    {
        path: '/extension',
        name: 'Extension',
        component: () =>
            import ('../views/extension.vue')
    },
    {
        path: '/profit',
        name: 'Profit',
        component: () =>
            import ('../views/profit.vue')
    },
    {
        path: '/404',
        name: '404',
        component: () =>
            import ('../views/Eorr.vue')
    },
    {
        path: "*",
        redirect: "/404"
    }
]



const router = new VueRouter({
    routes
})

// // 路由守卫【保安】
// router.beforeEach((to, from, next) => {
//     let isLogin = local.get('Code') ? true : false; // 获取登录的状态

//     // 如果登录过 且是登录成功的
//     if (isLogin) {
//         next() // 直接放行
//     } else {
//         // 否则
//         // 如果去的是登录页
//         if (to.path === '/') {
//             next() // 直接放行
//         } else {
//             next('/') // 如果去的是别的页面 直接跳转到登录页
//         }
//     }
// })

// 解决导航栏或者底部导航tabBar中的vue-router在3.0版本以上频繁点击菜单报错的问题。
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export default router